package com.xyht.sca_s.student_manage_system.modules.visitor.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.annotation.VisitorExcludeCheck;
import com.xyht.sca_s.student_manage_system.common.annotation.VisitorRequestCheck;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.visitor.entity.vo.SmsVisitorAllowVO;
import com.xyht.sca_s.student_manage_system.modules.visitor.entity.vo.SmsVisitorProcessVO;
import com.xyht.sca_s.student_manage_system.modules.visitor.entity.vo.SmsVisitorRegisterVO;
import com.xyht.sca_s.student_manage_system.modules.visitor.service.SmsVisitorRegisterService;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-04-16
 */
@SecretBody
@RestController
@VisitorRequestCheck
@RequestMapping("/visitor/smsVisitorRegister")
public class SmsVisitorRegisterController {
    @Autowired
    SmsVisitorRegisterService smsVisitorRegisterService;
    @Autowired
    JwtTokenUtil jwtTokenUtil;


    @ApiModelProperty("新增游客申请")
    @PostMapping("/visitor/smsVisitorRegisterAdd")

    public ResponseResult smsVisitorRegisterAdd(@RequestBody SmsVisitorRegisterVO smsVisitorRegister,HttpServletRequest request){
        String user_id =jwtTokenUtil.getUserIdByRequest(request);
        return smsVisitorRegisterService.smsVisitorRegisterAdd(smsVisitorRegister,user_id);
    }
    @ApiModelProperty("删除游客申请")
    @DeleteMapping("/deleteSmsVisitorRegister")

    public ResponseResult deleteSmsVisitorRegister(@RequestBody SmsVisitorRegisterVO smsVisitorRegister){
        return smsVisitorRegisterService.deleteSmsVisitorRegister(smsVisitorRegister);
    }
    @ApiModelProperty("修改游客申请")
    @PostMapping("/updateSmsVisitorRegister")
    public ResponseResult updateSmsVisitorRegister(@RequestBody SmsVisitorRegisterVO smsVisitorRegister){
        return smsVisitorRegisterService.updateSmsVisitorRegister(smsVisitorRegister);
    }
    @ApiOperation("游客查询申请")
    @GetMapping("/visitor/selectSmsVisitorRegister")
    public ResponseResult selectSmsVisitorRegister(
            HttpServletRequest request,
            @RequestParam(value = "register_state", required = false) Integer register_state,
                                                   @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                   @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                   @RequestParam(value = "bg_date", required = false) String bg_date,
                                                   @RequestParam(value = "end_date", required = false) String end_date){
        String visitor_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsVisitorRegisterService.selectSmsVisitorRegister(visitor_id,register_state,pageSize,pageNum,bg_date,end_date);
    }

    @ApiOperation("游客根据id查询游客申请")
    @GetMapping("/selectById")
    public ResponseResult selectById(@RequestParam(value = "id", required = false) String id,
                                     @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                     @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum
    ){
        return smsVisitorRegisterService.selectById(id,pageSize,pageNum);
    }
    @ApiOperation("教师根据id查询游客申请")
    @VisitorExcludeCheck
    @GetMapping("/selectByIdTeacher")
    public ResponseResult selectByIdTeacher(@RequestParam(value = "id", required = false) String id,
                                     @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                     @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum
    ){
        return smsVisitorRegisterService.selectByIdTeacher(id,pageSize,pageNum);
    }
    @ApiOperation("审批人查询游客申请")
    @VisitorExcludeCheck
    @GetMapping("/allowUser/selectByProcessPeople")
    public ResponseResult selectByProcessPeople(@RequestParam(value = "visitor_name", required = false) String visitor_name,
                                              HttpServletRequest request,
                                              @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                              @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                              @RequestParam(value = "bg_date", required = false) String bg_date,
                                              @RequestParam(value = "end_date", required = false) String end_date
    ){
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsVisitorRegisterService.selectByProcessPeople(visitor_name,user_id,pageSize,pageNum,bg_date,end_date);
    }



    @ApiOperation("查询未删除的游客申请")
    @GetMapping("/selectSmsVisitorRegisterOfWeb")
    public  ResponseResult selectSmsVisitorRegisterOfWeb(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                         @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum){
        return smsVisitorRegisterService.selectSmsVisitorRegisterOfWeb(pageSize,pageNum);
    }
    @ApiOperation("审批")
    @VisitorExcludeCheck
    @PostMapping("/allowUser/allow")
    public  ResponseResult selectSmsVisitorRegisterByAllow(@RequestBody SmsVisitorAllowVO smsVisitorAllow, SmsVisitorProcessVO smsVisitorProcessVO,HttpServletRequest request){
        String allow_person_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsVisitorRegisterService.selectSmsVisitorRegisterByAllow(smsVisitorAllow, smsVisitorProcessVO,allow_person_id);
    }

    @ApiOperation("二维码")
    @VisitorExcludeCheck
    @PostMapping("/scanQr")
    public ResponseResult scanQr(
            HttpServletRequest request,
            @RequestBody SmsVisitorRegisterVO smsVisitorRegisterVO){
        String scan_user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsVisitorRegisterService.scanQr(smsVisitorRegisterVO,scan_user_id);
    }
    @ApiOperation("保安扫描二维码后查看访客申请详情")
    @VisitorExcludeCheck
    @GetMapping("/selectSmsVisitorRegisterByQrId")
    public ResponseResult selectSmsVisitorRegisterByQrId(String qrId){
        return smsVisitorRegisterService.selectSmsVisitorRegisterByQrId(qrId);
    }
    @ApiOperation("保安查看访客扫描记录")
    @VisitorExcludeCheck
    @GetMapping("/selectSmsVisitorRegisterByBaoAn")
    public ResponseResult selectSmsVisitorRegisterByBaoAn(
            HttpServletRequest request,

                                                          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum
                                                          ){
        String scan_user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsVisitorRegisterService.selectSmsVisitorRegisterByBaoAn(scan_user_id,pageSize,pageNum);
    }
    @ApiOperation("保安查看访客申请记录详情")
    @VisitorExcludeCheck
    @GetMapping("/selectSmsVisitorRegisterById")
    public ResponseResult selectSmsVisitorRegisterById(String id){
        return smsVisitorRegisterService.selectSmsVisitorRegisterById(id);
    }

    @ApiOperation("访客通过电话查询被访人")
    @GetMapping("select")
    public ResponseResult selectSmsVisitorRegisterByPhone(@RequestParam(value = "phone_num", required = false) String phone_num){

        return smsVisitorRegisterService.selectSmsVisitorRegisterByPhone(phone_num);
    }

}

